<?php

declare(strict_types=1);

namespace Modules\Production\Models;

use Illuminate\Database\Eloquent\Relations\HasMany;
use Catch\Base\CatchModel as Model;

/**
 * @property $id
 * @property $production_order_id
 * @property $fseq
 * @property $fentryid
 * @property $fmaterialid1
 * @property $fmaterialname1
 * @property $fmaterialmodel1
 * @property $fmodel1
 * @property $fpositionno
 * @property $fnumerator
 * @property $fdenominator
 * @property $funitid1
 * @property $ffixscrapqty
 * @property $fscraprate
 * @property $fmustqty
 * @property $fpickedqty
 * @property $fsolidcollarqty
 * @property $ftranslateqty
 * @property $fnopickedqty
 * @property $frepickedqty
 * @property $fgoodreturnqty
 * @property $fsupplymode
 * @property $fmemo1
 * @property $creator_id
 * @property $created_at
 * @property $updated_at
 * @property $deleted_at
*/
class ProductionOrderDetail extends Model
{


    protected $table = 'production_order_detail';

    protected $fillable = [ 'id', 'production_order_id', 'fseq', 'fentryid','back_status','fownertypeid','fownerid_number','fownerid_name', 'fmaterialid1', 'fmaterialname1', 'fmaterialmodel1', 'fmodel1', 'fpositionno', 'fnumerator', 'fdenominator','funitid1_number','funitid1_name', 'funitid1', 'ffixscrapqty', 'fscraprate', 'fmustqty', 'fpickedqty', 'fsolidcollarqty', 'ftranslateqty', 'fnopickedqty', 'frepickedqty', 'fgoodreturnqty', 'fsupplymode','fproxyissuetype', 'fmemo1', 'creator_id', 'created_at', 'updated_at', 'deleted_at' ];

    /**
     * @var array
     */
    protected array $fields = ['id','production_order_id','fseq','fentryid','back_status','fownertypeid','fownerid_number','fownerid_name','fmaterialid1','fmaterialname1','fmaterialmodel1','fmodel1','fpositionno','fnumerator','fdenominator','funitid1_number','funitid1_name','funitid1','ffixscrapqty','fscraprate','fmustqty','fpickedqty','fsolidcollarqty','ftranslateqty','fnopickedqty','frepickedqty','fgoodreturnqty','fsupplymode','fproxyissuetype','fmemo1','created_at','updated_at'];

    /**
     * @var array
     */
    protected array $form = ['production_order_id','fseq','fentryid','back_status','fownertypeid','fownerid_number','fownerid_name','fmaterialid1','fmaterialname1','fmaterialmodel1','fmodel1','fpositionno','fnumerator','fdenominator','funitid1_number','funitid1_name','funitid1','ffixscrapqty','fscraprate','fmustqty','fpickedqty','fsolidcollarqty','ftranslateqty','fnopickedqty','frepickedqty','fgoodreturnqty','fsupplymode','fproxyissuetype','fmemo1','created_at','updated_at'];

    /**
     * @var array
     */
    public array $searchable = [
        'production_order_id' => '=',
        'fmaterialid1' => '=',
        'back_status' => '<>',
    ];

    /**
     * 时间格式化
     * @param $date
     * @return mixed
     */
    protected function serializeDate($date)
    {
        return $date->format('Y-m-d H:i');
    }

    /**
     * 关联生产入库头信息
     * @return mixed
     */
    public function order(){
        return $this->belongsTo(ProductionOrder::class,'production_order_id');
    }

    /**
     * 返回任务指派人员
     * @return HasMany
     */
    public function stockUser():HasMany
    {
        return $this->hasMany(ProductionOrderStockUser::class,'production_order_id','production_order_id');
    }


}
